package com.hzy.alibaba.config.redisson;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.ClusterServersConfig;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

/**
 * 集群
 */
public class DistributedLockClusterConfig {
    @Value("${redisson.password}")
    private String password;
    @Value("${redisson.nodeAddress}")
    private String[] nodeAddress;

    public DistributedLockClusterConfig() {
    }

    @Bean
    public Config config() {
        Config config = new Config();
        ((ClusterServersConfig)config.useClusterServers().setScanInterval(2000).setPassword(this.password)).addNodeAddress(this.nodeAddress);
        return config;
    }

    @Bean
    public RedissonClient redissonClient() {
        return Redisson.create(this.config());
    }

    @Bean
    public RedissonLocker redissonDistributedLock() {
        return new RedissonLocker(this.redissonClient());
    }
}
